﻿using System;
using System.Web;
using _5E.WebInfrastructure.Security;
using StoneAge.Controller.AsyncHandler;
using StoneAge.Controller.User;

namespace StoneAge.Controller.Request
{
    class WebRequestFactory : IWebRequestFactory
    {
        public WebRequest CreateWebRequestFrom(HttpContext context, AsyncCallback cb)
        {
            WebRequest webRequest = new WebRequest();
            webRequest.AsyncResult = new AjaxAsyncResult(context, cb);
            if (context.Request.IsAuthenticated)
            {
                if (null == context.User)
                {
                    throw new ArgumentNullException("context.User");
                }
                webRequest.User = (context.User as CustomFormsAuthentication<UserCookie>).UserData;
            }
            return webRequest;
        }
    }
}
